package com.semanticweb.webapp.dao.rbac;

import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.semanticweb.webapp.model.rbac.User;

/**
 * {@link UserDAO} implementation.
 * 
 * @author Vedran Cuca 19/2011
 * 
 */
@Repository
@Transactional
public class UserDAOHibernate extends AbstractGenericHibernateDao<User>
		implements UserDAO {
	
	 private static final Logger LOGGER = LoggerFactory.getLogger(UserDAOHibernate.class);

	@Override
	public User findByUsernameAndPassword(String username, String password) {
		LOGGER.info("find by username");
		return findByCriteriaUnique(Restrictions.eq(User.USERNAME, username),
				Restrictions.eq(User.PASSWORD, password));
	}

	@Override
	public User findByUsername(String username) {
		LOGGER.error("UserDAOHibernate username - " + username);
		return findByCriteriaUnique(Restrictions.eq(User.USERNAME, username));
	}

}
